package com.shenda.device.message;

import com.shenda.device.Constants;
import com.shenda.device.enums.Cjms;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 上传的总数据
 * 
 * @author lifeng
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class RespMsg_UploadStart extends RespMsg {

	private String message;
	private String startTime;// 开始时间 14
	private String endTime;// 结束时间 14
	private Cjms cjms; // 采集模式 2
	private String cjpl;// 采集频率 4
	private String odr; // 采集ODR 4
	private int length; // 采集长度 8
	private int frames; // 采集帧数
	private byte[] data;// 文件头数据

	@Override
	public int commandLength() {
		return 39;
	}

	@Override
	public RespMsg parse(byte[] data) {
		this.data = data;
		this.message = this.encodeHex(data);
		this.content = message.substring(8);
		this.startTime = message.substring(8, 22);
		this.endTime = message.substring(22, 36);
		this.cjms = Cjms.byCmd(message.substring(60, 62));
		this.cjpl = message.substring(62, 66);
		this.odr = message.substring(66, 70);
		String dataLength = message.substring(message.length() - 8);
		int length = Integer.parseInt(dataLength, 16);
		this.length = (length / Constants.iMinBlockSize) * Constants.iBlockSize;
		this.frames = (this.length / Constants.iMinBlockSize) * (Constants.iMinBlockSize / this.cjms.getRecord());
		return this;
	}
}